package com.example.myapplication.alarm;

import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.util.Log;
import android.widget.RemoteViews;

import androidx.annotation.RequiresApi;

import com.example.myapplication.DigitClock;
import com.example.myapplication.R;
import com.example.myapplication.alarm.AlarmManagerUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author:weng
 * @data:2022/11/8
 * @description:
 */

public class MyService extends Service {
    private static final String TAG = "MyService";

    public MyService() {

    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");

    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.e("tag","执行定时任务");

                ComponentName thisAppWidget = new ComponentName(getApplicationContext(),DigitClock.class);
           RemoteViews remoteViews=new RemoteViews(getApplicationContext().getPackageName(), R.layout.clock_layout);
           SimpleDateFormat format=new SimpleDateFormat("yyyy-MM--dd HH:mm:ss");
            remoteViews.setTextViewText(R.id.textView,format.format(new Date()));
                AppWidgetManager.getInstance(getApplicationContext()).updateAppWidget(thisAppWidget,remoteViews);

        AlarmManagerUtils.getInstance(getApplicationContext()).getUpAlarmManagerWorkOnOthers();
        return super.onStartCommand(intent, flags, startId);
    }



}
